package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.pojo.Orders;
import com.itheima.pojo.PageBean;
import com.itheima.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 小帅蓝
 * @Date 2022/6/21 9:43
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @GetMapping("/page")
    public R<PageBean> queryAll(String beginTime, String endTime, String number, Integer page, Integer pageSize) {
        List<Orders> ordersList = ordersService.queryAll(beginTime, endTime, number, page, pageSize);
        Integer total = ordersService.getCount(number, null);
        return R.success(new PageBean(ordersList, total, pageSize, page));
    }

    @PutMapping
    public R<String> updateStatus(@RequestBody Orders orders) {
        boolean result = ordersService.updateStatus(orders);
        return result ? R.success("修改成功") : R.error("修改失败");
    }

}
